define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'tongcheng/rider_enter/index' + location.search,
                    add_url: 'tongcheng/rider_enter/add',
                    edit_url: 'tongcheng/rider_enter/edit',
                    del_url: 'tongcheng/rider_enter/del',
                    multi_url: 'tongcheng/rider_enter/multi',
                    import_url: 'tongcheng/rider_enter/import',
                    table: 'tongcheng_rider_enter',
                }
            });

            var table = $("#table");

            // 在普通搜索渲染后
            table.on('post-common-search.bs.table', function (event, table) {
              let form = $("form", table.$commonsearch);

              $("input[name='zone_id']", form).addClass("selectpage").data("source", "tongcheng/zone/index").data("params", {"custom[status]": 1}).data("orderBy","id desc");
              // $("input[name='rider_id']", form).addClass("selectpage").data("source", "tongcheng/rider/index").data("params", {"custom[status]": 1}).data("field", "real_name").data("orderBy","id desc");
              $("input[name='user_id']", form).addClass("selectpage").data("source", "user/user/index").data("field", "nickname").data("orderBy","id desc");

              Form.events.cxselect(form);
              Form.events.selectpage(form);
            });

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('ID')},
                       
                        // {
                        //   field: 'zone.name', title: __('Zone.name'), operate: false, formatter: function (value, row, index) {
                        //     return value + '(' + row.zone_id + ')';
                        //   }
                        // },
                    
                        {field: 'real_name', title: __('Real_name'), operate: 'LIKE'},
                        {field: 'mobile', title: __('Mobile'), operate: 'LIKE'},
                        // {field: 'gender', title: __('Gender'), searchList: {"0":'女',"1":'男'}, formatter: Table.api.formatter.status},
                        {field: 'sid_z', title: __('Sid z'), operate: false},
                        // {field: 'sidf', title: __('Sid f'), operate: false},
                        {field: 'drive_z', title: __('Drive z'), operate: false},
                        // {field: 'drivef', title: __('Drive f'), operate: false},
                        {field: 'car_z', title: __('Car z'), operate: false},
                        // {field: 'carf', title: __('Car f'), operate: false},
                        {field: 'car_m', title: __('Car m'), operate: 'LIKE'},
                        {field: 'car_insure', title: __('Car insure'), operate: false},
                        {field: 'sys_insure', title: __('Sys insure'), operate: 'LIKE', searchList: {"0":__('Sys insure 0'),"1":__('Sys insure 1')}, formatter: Table.api.formatter.status},
                        {field: 'car_statue', title: __('Car statue'), operate: 'LIKE',searchList: {"0":__('Car statue 0'),"1":__('Car statue 1')}, formatter: Table.api.formatter.status},
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1'),"2":__('Status 2')}, formatter: Table.api.formatter.status},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {
                            field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
                             buttons: [
                                {
                                  name: 'details',
                                  text: '查看详情',
                                  title: '查看详情',
                                  icon: 'fa fa-list',
                                  classname: 'btn btn-xs btn-success btn-dialog btn-config',
                                  extend: 'data-area=\'["60%", "80%"]\'',
                                  url: function (row) {
                                      console.log('row', row);
                                      return '';
                                  },
                                },
                             
                            ],
                            // formatter: Table.api.formatter.operate,
                            formatter: function (value, row, index) {
                                var that = $.extend({}, this);
                                var table = $(this.table).clone(true);

                                // 已审核的隐藏编辑和删除
                                if (row.status != 0) {
                                    // $(table).data('operate-edit', null);
                                    // $(table).data('operate-del', null);
                                }

                                that.table = table;
                                return Table.api.formatter.operate.call(that, value, row, index);
                            },
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        recyclebin: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    'dragsort_url': ''
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: 'tongcheng/rider_enter/recyclebin' + location.search,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'name', title: __('Name'), align: 'left'},
                        {
                            field: 'deletetime',
                            title: __('Deletetime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'operate',
                            width: '140px',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'Restore',
                                    text: __('Restore'),
                                    classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
                                    icon: 'fa fa-rotate-left',
                                    url: 'tongcheng/rider_enter/restore',
                                    refresh: true
                                },
                                {
                                    name: 'Destroy',
                                    text: __('Destroy'),
                                    classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
                                    icon: 'fa fa-times',
                                    url: 'tongcheng/rider_enter/destroy',
                                    refresh: true
                                }
                            ],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },

        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
